package com.ericom.webapp.action;

import java.util.List;

import com.ericom.model.OrderShippingInfo;
import com.ericom.service.GenericManager;

public class OrderShippingInfoAction extends BaseAction {

	private GenericManager<OrderShippingInfo, Long> orderShippingInfoManager;
	private List orderShippingInfos;
	private OrderShippingInfo orderShippingInfo;
	private Long id;

	public OrderShippingInfo getOrderShippingInfo() {
		return orderShippingInfo;
	}

	public void setOrderShippingInfo(OrderShippingInfo orderShippingInfo) {
		this.orderShippingInfo = orderShippingInfo;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public void setOrderShippingInfoManager(
			GenericManager<OrderShippingInfo, Long> orderShippingInfoManager) {
		this.orderShippingInfoManager = orderShippingInfoManager;
	}

	public String list() {
		orderShippingInfos = orderShippingInfoManager.getAll();
		return SUCCESS;
	}

	public List getOrderShippingInfos() {
		return orderShippingInfos;
	}

	public String delete() {
		orderShippingInfoManager.remove(orderShippingInfo.getId());
		this.saveMessage(getText("orderShippingInfo.deleted"));
		return this.SUCCESS;
	}

	public String edit() {
		if (id != null) {
			orderShippingInfo = orderShippingInfoManager.get(id);
		} else {
			orderShippingInfo = new OrderShippingInfo();
		}
		return this.SUCCESS;
	}

	public String save() throws Exception {
		if (this.cancel != null) {
			return this.CANCEL;
		}
		if (this.delete != null) {
			return this.delete();
		}

		boolean isNew = (orderShippingInfo.getId() == null);
		orderShippingInfo = orderShippingInfoManager.save(orderShippingInfo);

		String key = (isNew) ? "orderShippingInfo.added"
				: "orderShippingInfo.updated";
		this.saveMessage(getText(key));

		if (!isNew) {
			return this.INPUT;
		} else {
			return this.SUCCESS;
		}
	}
}
